# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libglade
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.6.4
pkgrel=5
pkgdesc="Allows you to load glade interface files in a program at runtime (mingw-w64)"
arch=(any)
url="https://www.gnome.org"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gtk2>=2.16.0"
         "${MINGW_PACKAGE_PREFIX}-libxml2>=2.7.3")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
optdepends=("${MINGW_PACKAGE_PREFIX}-python2: libglade-convert script")
options=('staticlibs' 'strip')
source=(https://download.gnome.org/sources/${_realname}/2.6/${_realname}-${pkgver}.tar.bz2
        libglade-2.0.1-nowarning.patch
        libglade-secondary.patch
        libglade-link-against-gmodule.patch)
sha256sums=('64361e7647839d36ed8336d992fd210d3e8139882269bed47dc4674980165dec'
            '423c12af1c73442caa851a0b8db33b00fa4b778b1b422a4e8ac33d121d043008'
            '4f0317b27127f1fc676716bff11fade2de80f146e990700b11be7f0a5ee10d52'
            '934e5f184a662d823b35e98f346df8742fa0695df7b35925451132acdb582c52')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/libglade-2.0.1-nowarning.patch
  patch -p1 -i "${srcdir}"/libglade-link-against-gmodule.patch
  patch -p1 -i "${srcdir}"/libglade-secondary.patch

  WANT_AUTOMAKE=latest autoreconf -fi
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  PYTHON=${MINGW_PREFIX}/bin/python2 \
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install -j1
  install -m755 libglade-convert "${pkgdir}${MINGW_PREFIX}/bin/"
}
